//
// NewImageDialog.java
//

package com.photoexpert;

class NewImageDialog extends javax.swing.JDialog {

    static NewImageDialog Instance() {
        if(_instance == null)
            _instance = new NewImageDialog();
        return _instance;
    }

    private NewImageDialog() {
        super(App.Instance(), true);
        initComponents();
        setLocation(200, 200);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _widthLabel = new javax.swing.JLabel();
        _width = new javax.swing.JTextField();
        _heightLabel = new javax.swing.JLabel();
        _height = new javax.swing.JTextField();
        _transparent = new javax.swing.JCheckBox();
        _cancel = new javax.swing.JButton();
        _ok = new javax.swing.JButton();

        setTitle("New Image");
        setModal(true);
        setResizable(false);

        _widthLabel.setText("Width:");

        _width.setText("800");

        _heightLabel.setText("Height:");

        _height.setText("600");

        _transparent.setText("Allow transparency");

        _cancel.setText("Cancel");
        _cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _cancelActionPerformed(evt);
            }
        });

        _ok.setText("OK");
        _ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _okActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_heightLabel)
                            .addComponent(_widthLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_height, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                            .addComponent(_width, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)))
                    .addComponent(_transparent)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(_cancel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_widthLabel)
                    .addComponent(_width, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_heightLabel)
                    .addComponent(_height, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(_transparent)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_cancel)
                    .addComponent(_ok))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__okActionPerformed
    int width = Integer.parseInt(_width.getText());
    int height = Integer.parseInt(_height.getText());
    boolean transparent = _transparent.isSelected();
    Implementor.Instance().newImage(width, height, transparent);
    setVisible(false);
}//GEN-LAST:event__okActionPerformed

private void _cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__cancelActionPerformed
    setVisible(false);
}//GEN-LAST:event__cancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _cancel;
    private javax.swing.JTextField _height;
    private javax.swing.JLabel _heightLabel;
    private javax.swing.JButton _ok;
    private javax.swing.JCheckBox _transparent;
    private javax.swing.JTextField _width;
    private javax.swing.JLabel _widthLabel;
    // End of variables declaration//GEN-END:variables
    private static NewImageDialog _instance = null;
}
